package com.ctms.system.controller;

import com.ctms.common.utils.PageUtils;
import com.ctms.common.utils.Query;
import com.ctms.common.utils.R;
import com.ctms.system.domain.CommitTaskDO;
import com.ctms.system.domain.CorrectsTaskDO;
import com.ctms.system.domain.UserDO;
import com.ctms.system.service.CorrectsTaskService;
import com.ctms.system.service.TaskReleaseService;
import com.ctms.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RequestMapping("/scoreCommitTask")
@Controller
//给学生提交的作业进行打分页面
public class ScoreCommitTaskController {

    @Autowired
    UserService userService;
    @Autowired
    TaskReleaseService taskReleaseService;
    @Autowired
    CorrectsTaskService correctsTaskService;


/*
    @GetMapping("")
    public String score(){
        return "500";
    }
*/

    @GetMapping("/show/{tid}")
    public String show(Model model, @PathVariable("tid") Integer tid){
        model.addAttribute("tid",tid);
        return "sys/taskRelease/correctsTask";
    }

    @GetMapping("/list")
    @ResponseBody
    PageUtils list(@RequestParam Map<String,Object> params){
        int tid = Integer.parseInt(String.valueOf(params.get("taskId")));
        Query query = new Query(params);
        List<CorrectsTaskDO> correctsTaskDOS = correctsTaskService.selectAllTask(params);
        int total = correctsTaskService.count(params);
        PageUtils pageUtils = new PageUtils(correctsTaskDOS,total);
        return pageUtils;
    }

    @GetMapping("/corrects/{id}")
    public String corrects(Model model,@PathVariable("id")Integer id){
        model.addAttribute("sid",id);
        return "sys/taskRelease/score";
    }

    @PostMapping("/score")
    @ResponseBody
    R correctsTask(CorrectsTaskDO correctsTaskDO){
        if (correctsTaskService.updateCorrectsScore(correctsTaskDO)>0){
            return R.ok();
        }else {
            return R.error();
        }
    }

}
